package free.grnadav.jquerymobilegwt.client.page.header;

import java.util.Iterator;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;

public class PageHeader extends Composite implements  HasWidgets {
//	HasText,
	private static PageHeaderUiBinder uiBinder = GWT
			.create(PageHeaderUiBinder.class);

	interface PageHeaderUiBinder extends UiBinder<Widget, PageHeader> {
	}

	@UiField
	FlowPanel header;
	
	Element titleContainer = DOM.createElement("h1");
	
	private String text;

	public PageHeader() {
		initWidget(uiBinder.createAndBindUi(this));
		init();
	}
	
	private void init() {
		header.getElement().setAttribute("data-role", "header");
		// default no back button
		header.getElement().setAttribute("data-backbtn", "false");
	}
	
	public PageHeader(String text) {
		initWidget(uiBinder.createAndBindUi(this));
		init();
		setText(text);
	}


	public void setText(String text) {
		this.text = text;
		header.getElement().appendChild(titleContainer);
		titleContainer.setInnerText(text);
	}

	public String getText() {
		return text;
	}

	@Override
	public void add(Widget w) {
		header.add(w);
	}

	@Override
	public void clear() {
		header.clear();
	}

	@Override
	public Iterator<Widget> iterator() {
		return header.iterator();
	}

	@Override
	public boolean remove(Widget w) {
		return header.remove(w);
	}

}
